/* 行
 * @param {String}
 */


function get(url, funSuccess, funComplete) {
	uni.showLoading({
		title: 'jiazaizhong....',
		mask: false
	});
	uni.request({
			url,
			method: 'GET',
			header: {
				"content-type": "application/json;charset=UTF-8"
			},
			
			sslVerify: false,
			success: res => {
				funSuccess(res.data);
			},
			fail: err => {
				console.log(err);
			},
			complete: () => {
				uni.hideLoading();
				funComplete();
			}
		});
	
	}
	
	/**
	 * post请求
	 *	@param {String} url 要请求的接口地址
	 *	@param {JSON} data 要提交的数据
	 *	@param {Function} funSuccess 成功的回调
	 *	@param {Function} funComplete 请求结束的回调，如果无需处理则传递一个空方法即可
	 */
	function post(url, data, funSuccess, funComplete) {
		uni.showLoading({
			title: '提交数据.....',
			mask: false
		});
		uni.request({
			url,
			method: 'POST',
			data: data,
			success: res => funSuccess(res.data),
			fail: err => {
				console.log(err);
			},
			complete: () => {
				uni.hideLoading();
				funComplete();
			}
		});
	}


function getWithHeader(url, header, funSuccess, funComplete) {
	uni.showLoading({
		title: 'jiazaizhong....',
		mask: false
	});
	uni.request({
		url,
		header,
		method: 'GET',
		sslVerify: false,
		data: {},
		success: res => {
			funSuccess(res.data);
		},
		fail: () => {},
		complete: () => {
			uni.hideLoading();
			funComplete();
		}
	});

}

function postParam(url, data, funSuccess, funComlete) {
	uni.showLoading({
		title: '提交数据',
		mask: false
	});

	uni.request({
		url,
		header: {
			"Accept": "application/json; q=0.9, */*; q=0.1",
			"Content-Type": "application/x-www-form-urlencode;charset=UTF-8"
		},
		method: 'POST',
		sslVerify: false,
		data: data,
		success: res => funSuccess(res.data),
		fail: err => {
			console.log(err);
		},
		complete: () => {
			uni.hideLoading();
			funComlete();
		},
	});
}
function deleteParams(url,data, funSuccess, funComplete) {

	uni.request({
		url,
		
		header: {
			/* q=qualify*/
			"Accept": "application/json;q=0.9, */*; q=0.1",
			"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
		},
		method: 'DELETE',
		sslVerify: false,
		data:data,
		success: res => funSuccess(res.data),
		
		fail: err => {
			console.log(err);
		},
		complete: () => {

			funComplete();
		}
	});
}
function postFile(url, name, filePath, data, funSuccess){
	uni.uploadFile({
		url,
		name,
		filePath,
		formData:data,
		success:res => funSuccess(res)
	})
}
module.exports = {
	get,
	getWithHeader,
	postParam,
	post,
	deleteParams,
	postFile
}
